var ns,  app;
app = new Vue({
    el: '#app',
    data: {
        ID:0,
        form: {},
        process:[],
        Patrol:[],
        IsRoomOpen:false,
        IsRoomOpenid:0,//0--暂停，1--恢复
        IsOpenResult:false,
        remark:'',//装修暂停说明
        OperateTime:'',//当前时间
        Resultdata:{},
    },
    methods: {
        getdata:function(){
            var that=this;
            var options = {};
            options.RegisterID = that.ID;
            options.action = "getdecorationdetails";
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    that.form = data.newModel;
                    that.process=data.process;
                    that.Patrol=data.Patrol;
                } else {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            })
        },
        do_open_zxMsg:function(id){
            var that=this;
            ns.openWin('zxMsg_frm', '装修信息',{
                ID:id
            });
        },
        do_open_step:function(){
            var that=this;
            ns.openWin('zxStep_frm', '装修进程',{
                ID:that.ID
            });
        },
        do_search:function(){
            var that=this;
            ns.openWin('zxchayan_frm', '装修查验',{
                ID:that.ID
            });
        },
        //查看巡查结果
        do_openresult:function(CheckResult,id,state,xctype){
            var that = this;
            if(CheckResult==0){
                if(state==true){
                    if(xctype==1||xctype==2){
                        ns.openWin('xcResult_frm', '装修巡查',{
                            ID:id,
                            type:xctype
                        });
                    }else{
                        ns.openWin('zxchayan_frm', '装修查验',{
                            ID:id,
                            type:xctype
                        });
                    }
                    

                }else{
                    api.toast({
                        msg: "您不是巡查人,不能巡查任务",
                        duration: 2000,
                        location: 'bottom'
                    });
                }
                
            }
            if(CheckResult==1||CheckResult==2){
                that.IsOpenResult=true;
                that.do_resultMsg(id);
            }
        },

        //结果页面
        do_resultMsg:function(id){
            var that=this;
            var options = {};
            options.ID = id;
            options.action = "gettaskdetailrecord";
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    that.Resultdata = data;
                } else {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            })

        },
        //装修暂停保存
        do_savestop:function(type){
            var that=this;
            var options = {};
            options.ID = that.ID;
            options.Type = type;
            options.ContentDesc = that.remark;
            options.OperateTime = that.OperateTime;
            options.action = "registerisstop";
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    if(data.status){
                        that.IsRoomOpen=false;
                        if(type==4){
                            that.IsRoomOpenid=1;
                        }
                        if(type==5){
                            that.IsRoomOpenid=0;
                        } 
                        api.sendEvent({
                            name: 'isStop',
                        });                      
                    }
                } else {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            })
        },


        //结算
        // do_result:function(){
        //     var that=this;
        //     ns.openWin('zxjiesuan_frm', '装修结算',{
        //         ID:that.ID
        //     });
        // },
         //装修巡查
         do_zxXuncha:function(type){
            var that=this;
            ns.openWin('xcResult_frm', '装修巡查',{
                ID:that.ID,
                type:type
            });
        },
        //暂停装修
        do_stop: function (type) {
            var that = this;
            that.IsRoomOpen=true;
            if(type==4){
                that.IsRoomOpenid=0
            }
            if(type==5){
                that.IsRoomOpenid=1
            }
        },
        //关闭弹窗
        doCloseRoom:function(){
            var that=this;
            that.IsRoomOpen=false;
            that.IsOpenResult=false;
        },
        img_browser: function(item) {
            var that = this;
            var imgurls = [];
            imgurls.push(item.SysFinalFilePath);
            imageBrowser.openImages({
                imageUrls: imgurls,
                showList: false,
                activeIndex: 0
            });
        },

    }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    imageBrowser = api.require('imageBrowser');
    app.ID = api.pageParam.ID || 0;
    app.IsRoomOpenid = api.pageParam.IsRoomOpenid;
    var data = new Date();
    var year = data.getFullYear();
    var month = data.getMonth() + 1;
    var day=data.getDate();
    app.OperateTime = year + '-' + (month >= 10 ? month : '0' + month)+'-'+(day >= 10 ? day : '0' + day);
    app.getdata();
    api.addEventListener({
        name: 'xuncha_updata'
    }, function () {
        app.getdata();
    });
    api.addEventListener({
        name: 'chayan_updata'
    }, function () {
        app.getdata();
    });
    api.addEventListener({
        name: 'zhuanjiao_updata'
    }, function () {
        app.getdata();
    });
};
